package edu.lyun.stumvc.service.impl;

import edu.lyun.stumvc.entity.Student;
import edu.lyun.stumvc.entity.vo.request.StudentRequest;
import edu.lyun.stumvc.mapper.StudentMapper;
import edu.lyun.stumvc.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    StudentMapper mapper;

    @Override
    @Transactional
    public List<StudentRequest> selectAllFromStudents() {
        List<Student> students = mapper.selectAllFromStudents();
        return students.stream().map(i -> i.asViewObject(StudentRequest.class, v -> v.setDisplay(false))).toList();
    }

    @Override
    @Transactional
    public int deleteStudentsWhereIdEqual(int id) {
        return mapper.deleteStudentsWhereIdEqual(id);
    }

    @Override
    @Transactional
    public int updateStudentsByStudent(Student student) {
        return mapper.updateStudentsByStudent(student);
    }

    @Override
    @Transactional
    public int insertIntoStudentsByStudent(Student student) {
        return mapper.insertIntoStudentsByStudent(student);
    }
}
